﻿namespace Iptv.ResourceDowner.Helper
{
    /// <summary>
    /// 流量计算助手
    /// </summary>
    public class FlowAssistantor
    {
        System.Threading.Timer timer;
        /// <summary>
        /// 构造函数
        /// </summary>
        public FlowAssistantor()
        {
            ReadSize = 0;
            FlowSize = 0;
            timer = new System.Threading.Timer(new System.Threading.TimerCallback(timerCall), null, 0, 1000);
        }

        long timeSize = 0;
        /// <summary>
        /// 读取的字节数
        /// </summary>
        public long ReadSize { set; get; }
        /// <summary>
        /// 速度/流量
        /// </summary>
        public long FlowSize { get; set; }

        private void timerCall(object a)
        {
            FlowSize = ReadSize - timeSize;
            //LogHelper.WriteDebugLogEx(string.Format("当前线程ReadSize{0} TimeSize{1} FlowSize为{2}  {3}MB/s", ReadSize, timeSize, FlowSize, Math.Round((double)FlowSize / (1024 * 1024), 2)));
            timeSize = ReadSize;

        }
    }
}
